package com.wisdom.benefit.jufa.my;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.wisdom.benefit.jufa.R;
import com.wisdom.benefit.jufa.base.BaseActivity;
import com.wisdom.benefit.jufa.utils.DataCleanManager;
import com.wisdom.benefit.jufa.utils.DialogUtil;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import cn.ycbjie.ycstatusbarlib.bar.YCAppBar;


/**
 * 设置页面
 */
public class SettingActivity extends BaseActivity {
    private TextView bigTv;
    private String bigValue;
    private RelativeLayout backRl, wipeRl, versionInfoRl, changePsdRl,runningRl;
    public static SettingActivity instance;

    @Override
    protected int getLayout() {
        return R.layout.activity_setting;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        instance = this;
    }

    @Override
    protected void initViews() {
        //缓存大小
        bigTv = findViewById(R.id.setting_big_tv);
        //返回按钮
        backRl = findViewById(R.id.setting_back);
        //清除缓存
        wipeRl = findViewById(R.id.setting_wipe_cache);
        //版本信息
        versionInfoRl = findViewById(R.id.setting_version_information);
        //修改密码
        changePsdRl = findViewById(R.id.setting_change_password);
        //运行权限设置
        runningRl = findViewById(R.id.setting_running);
        setClick();
        setData();
    }

    /**
     * 设置监听
     */
    private void setClick() {
        //返回按钮
        backRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //清除缓存
        wipeRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog();
            }
        });
        //修改密码
        changePsdRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SettingActivity.this, ChangePasswordActivity.class);
                startActivity(intent);
            }
        });
        //运行权限设置
        runningRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SettingActivity.this, RunPermissionSettingsActivity.class);
                startActivity(intent);
            }
        });
        //设置状态栏为蓝色
        YCAppBar.setStatusBarColor(SettingActivity.this,
                ContextCompat.getColor(SettingActivity.this,
                        R.color.blue));
        //版本信息
        versionInfoRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SettingActivity.this, VersionInformationActivity.class);
                startActivity(intent);
            }
        });
    }

    /**
     * 设置数据
     */
    private void setData() {
        //获取缓存大小
        try {
            bigValue = DataCleanManager.getTotalCacheSize(SettingActivity.this);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //缓存大小
        bigTv.setText(bigValue);
    }

    @Override
    protected int getTitleStringRes() {
        return 0;
    }

    private void dialog() {
        DialogUtil dialogUtil = new DialogUtil(SettingActivity.this, SettingActivity.this);
        dialogUtil.dialog("提示", "确定要清除缓存？", "取消", "确定","1");
        dialogUtil.setOnItemClickListener(new DialogUtil.OnItemClickListener() {
            @Override
            public void onItemCancelClick() {
                Log.d("onItemClick", "你点击了取消");
            }

            @Override
            public void onItemConfirmClick() {
                boolean a = DataCleanManager.clearAllCache(SettingActivity.this);
                if (a == true) {
                    Toast.makeText(SettingActivity.this, "已清空", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onItemValueConfirmClick(String a) {

            }
        });
    }
}
